package com.psbc.springbootstudydemo1.controller;

import com.psbc.springbootstudydemo1.domain.User;
import com.psbc.springbootstudydemo1.service.UserService;
import com.psbc.springbootstudydemo1.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/pub/user")
public class UserController {
    //    @PostMapping("login")
//    public JsonData login(String pwd,String name){
//        System.out.println("pwd: " + pwd + " name: " + name);
//        return JsonData.buildSuccess("");
//    }
    @Autowired
    public UserService userService;
    @PostMapping("login")
    public JsonData login(@RequestBody User user) {
        System.out.println("user= " + user.toString());
        String token = userService.login(user.getName(), user.getPwd());
        return token != null ? JsonData.buildSuccess(token) : JsonData.buildError("账号密码错误");
    }
    @GetMapping("userlist")
    public JsonData userList(){
        return JsonData.buildSuccess(userService.userList());
    }
}
